package com.qiangqiang.resoldhouse.controller;

import com.qiangqiang.resoldhouse.dto.CommentDTO;
import com.qiangqiang.resoldhouse.dto.PageDTO;
import com.qiangqiang.resoldhouse.entity.Comment;
import com.qiangqiang.resoldhouse.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: zqh
 * @date: 2018/8/15 10:08
 * @description:
 */
@Controller
public class CommentController {

    @Autowired
    private CommentService commentService;

    //查看经纪人所有评价
    @ResponseBody
    @RequestMapping("/ajax_comment_list")
    public Map getAjaxPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam Long agentId){
        Map<String, Object> map = new HashMap<>();

        PageDTO<CommentDTO> pageDTO = commentService.findCommentsByAgentId(page,agentId);

        map.put("result", pageDTO.getResult());
        map.put("current", pageDTO.getPage().getCurrent());
        map.put("pages", pageDTO.getPage().getPages());
        map.put("hasPrePage", pageDTO.getPage().hasPrevious());
        map.put("hasNextPage", pageDTO.getPage().hasNext());
        map.put("total", pageDTO.getPage().getTotal());
        return map;
    }

    //用户在个人中心评价已完成的预约
    @RequestMapping("/add_comment")
    public String addComment(Comment comment){
        commentService.addComment(comment);
        return "redirect:/user/user_appointment_list";
    }
}
